#include "spmts.h"


// 负责项目的准备工作，例如：分配内存、加载数据、初始化全局变量
void init_spmts(void)
{
	cnt_administrator=load_data(administrator,sizeof(administrator),"administrator.dat")/sizeof(Administrator);
	cnt_logistics=load_data(logistics,sizeof(logistics),"logistics.dat")/sizeof(Logistics);
	cnt_vip=load_data(vip,sizeof(vip),"vip.dat")/sizeof(Vip);
	cnt_payment=load_data(payment,sizeof(payment),"payment.dat")/sizeof(Payment);
	cnt_goods=load_data(goods,sizeof(goods),"goods.dat")/sizeof(Goods);
}

// 进入项目的业务流程
void start_spmts(void)
{
	for(;;)
	{
		menu();
		switch(get_cmd('0','9'))
		{
			case '1':enroll_administrator();break;
			case '2':login_administrator();break;
			case '3':login_logistics();break;
			case '4':cashier();break;
			case '0':return;
		}
	}
}

// 负责项目的收尾工作，例如：保存数据、释放内存
void exit_spmts(void)
{
	save_data(logistics,sizeof(Logistics)*cnt_logistics,"logistics.dat");	 
	save_data(vip,sizeof(Vip)*cnt_vip,"vip.dat");
	save_data(payment,sizeof(Payment)*cnt_payment,"payment.dat");
	save_data(goods,sizeof(Goods)*cnt_goods,"goods.dat");
	save_data(administrator,sizeof(Administrator)*cnt_administrator,"administrator.dat");
}
